Skip to content

【iOS】Fixes ellipsis carries background from trimmed text#39408

Closed
zhongwuzw wants to merge 13 commits into
facebook:mainfrom
zhongwuzw:features/fix_ellipsis_background
Closed

【iOS】Fixes ellipsis carries background from trimmed text#39408
zhongwuzw wants to merge 13 commits into
facebook:mainfrom
zhongwuzw:features/fix_ellipsis_background

Conversation

@zhongwuzw
Copy link
Copy Markdown
Contributor

Summary:

Fixes #37926.

Changelog:

[IOS] [FIXED] - Fixes ellipsis carries background from trimmed text

Test Plan:

Demo code:

<Text numberOfLines={1} ellipsizeMode={'tail'}>Long text <Text style={{backgroundColor: 'red'}}>Nested text</Text></Text>

Before fix:
image

After fix:
image

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 12, 2023
@javache
Copy link
Copy Markdown
Member

javache commented Sep 12, 2023

I don't think we want to mutate _textStorage in the draw path. Would it be possible to do so in the layout path? Also, could you verify this behaviour in the new architecture too?

@analysis-bot
Copy link
Copy Markdown

analysis-bot commented Sep 12, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 21,284,129 +49,399
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 24,481,163 +49,241
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 778fcec
Branch: main

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

I don't think we want to mutate _textStorage in the draw path. Would it be possible to do so in the layout path? Also, could you verify this behaviour in the new architecture too?

@javache Thanks for the review, I have no idea how to do it in the layout path, my thought is we can mutate the textStorage before drawing and restore the textStorage which we mutated after drawing.

And I tested in new arch and it has the same issue.

@javache
Copy link
Copy Markdown
Member

javache commented Sep 13, 2023

I would look at making this change in RCTTextShadowView and RCTTextLayoutManager (for the new architecture)

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

@javache Friendly ping, thank you for any feedback :)

Copy link
Copy Markdown
Member

@javache javache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my previous feedback about moving this logic on the background thread by using RCTTextShadowView/RCTTextLayoutManager. Please also ensure this is compatible with the new architecture.

@zhongwuzw zhongwuzw force-pushed the features/fix_ellipsis_background branch from 08df8de to aadbf6f Compare October 17, 2023 02:17
@zhongwuzw zhongwuzw requested a review from javache October 17, 2023 06:18
layoutContext,
layoutConstraints,
nullptr);
hostTextStorage_);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems Fabric uses different textStorage in measure and draw path. We should share it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2024

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 8, 2024
@zhongwuzw
Copy link
Copy Markdown
Contributor Author

zhongwuzw commented May 10, 2024

@javache Seems we can't put it into background thread In new arch, because we use separate textstorage for measure and draw path, shared of textstorage was removed in #43914.

@github-actions github-actions Bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label May 11, 2024
@zhongwuzw
Copy link
Copy Markdown
Contributor Author

any one can help to review? cc. @sammy-SC @javache

@javache
Copy link
Copy Markdown
Member

javache commented Jul 9, 2024

Thanks for investigating this. The changes look reasonable, but can we add gating here so we only execute this if numberOfLines is set?

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

@javache Done :)

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cipolleschi
Copy link
Copy Markdown
Contributor

Hi @zhongwuzw, I know that you are fixing a specific issue, but there could be other style properties that we want to remove from the ellipsis.

I think that the ellispis should keep the same style of the character that precedes it, not to have weird artifacts on the screen.
what do you think?

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

@cipolleschi Hi, I just keep the same color related attributes as the character that precedes it. Other attributes like fontSize would impact the layout of the text.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@javache
Copy link
Copy Markdown
Member

javache commented Jul 10, 2024

This is failing internal builds with

packages/react-native/Libraries/Text/Text/RCTTextShadowView.mm:262:64: error: declaration shadows a local variable [-Werror,-Wshadow]
                                     NSTextContainer *_Nonnull textContainer,

packages/react-native/Libraries/Text/Text/RCTTextShadowView.mm:263:46: error: declaration shadows a local variable [-Werror,-Wshadow]
                                     NSRange glyphRange,

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

@javache done 😀

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 11, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache merged this pull request in fcb6cdc.

@github-actions
Copy link
Copy Markdown

This pull request was successfully merged by @zhongwuzw in fcb6cdc.

When will my fix make it into a release? | How to file a pick request?

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been reverted by b1c5432.

facebook-github-bot pushed a commit that referenced this pull request Jul 15, 2024
…5412)

Summary:
Reland #39408 . Try to fix the crash #37926 (comment). cc. javache I changed the range from glyph to character because all attributes related APIs are character range.

## Changelog:

[IOS] [FIXED] - Fixes ellipsis carries background from trimmed text

Pull Request resolved: #45412

Test Plan: #37926 .

Reviewed By: cipolleschi

Differential Revision: D59681679

Pulled By: javache

fbshipit-source-id: de4cb73e0304b8c0b0a40f4f6838b2c679747009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Reverted Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] Ellipsis carries background from trimmed text

5 participants